<%-- 
    Document   : sensors
    Created on : Jun 3, 2011, 8:08:22 PM
    Author     : Andrej Kuročenko <kurochenko@gmail.com>
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<c:if test="${not empty groups}" >
    <div>
        <form method="post" action="${pageContext.request.contextPath}/?location=${param.location}" id="sensorGroup">
            <div id="sensors">
                <ul>
                    <c:forEach var="group" items="${groups.keySet()}" >
                        <li><input type="checkbox" name="group[${group}]" id="${group}Name" class="groupBox" />
                            (${groups.get(group).size()} &times;)&#10;<a href="javascript:showHide('${group}id')">${group}</a>

                            <ul id="${group}id" class="hiddenGroup">
                                <c:forEach var="sensor" items="${groups.get(group)}" >
                                    <li><input type="checkbox" name="sensors" value="${sensor.id}"
                                               id="${sensor.name}" class="${group}Name" onclick="checkChecked('${group}Name');" 
                                               ${fn:contains(toVisualize, sensor.id) ? "checked=\"checked\"" : ""} />
                                        <label for="${sensor.name}">${sensor.name}</label>
                                    </li>    
                                </c:forEach>
                            </ul>                 
                        </li>    
                    </c:forEach>
                </ul>
            </div>
            <div id="metadata">
                <label for="sensorAction">Choose visualisation type:</label><br />
                <select name="sensorAction" id="sensorAction">                
                    <c:set var="tempSensorAction" value="plot_all" />
                    <c:choose>

                        <c:when test="${tempSensorAction.equals(param.sensorAction)}" >
                            <option value="plot_all" selected=\"selected\">Visualize as plot (all sensors in same plot)</option>
                        </c:when>

                        <c:otherwise>
                            <option value="plot_all">Visualize as plot (all sensors in same plot)</option>
                        </c:otherwise>
                    </c:choose>

                    <c:set var="tempSensorAction" value="plot_single" />
                    <c:choose>

                        <c:when test="${tempSensorAction.equals(param.sensorAction)}" >
                            <option value="plot_single" selected=\"selected\">Visualize as plot (each sensor in new plot)</option>
                        </c:when>
                        <c:otherwise>
                            <option value="plot_single">Visualize as plot (each sensor in new plot)</option>
                        </c:otherwise>
                    </c:choose>

                    <c:set var="tempSensorAction" value="map" />
                    <c:choose>

                        <c:when test="${tempSensorAction.equals(param.sensorAction)}" >
                            <option value="map" selected=\"selected\">Visualize as map (each sensor in new map)</option>
                        </c:when>
                        <c:otherwise>
                            <option value="map">Visualize as map (each sensor in new map)</option>
                        </c:otherwise>
                    </c:choose>

                    <c:set var="tempSensorAction" value="xml" />
                    <c:choose>

                        <c:when test="${tempSensorAction.equals(param.sensorAction)}" >
                            <option value="xml" selected=\"selected\">Export to XML file</option>
                        </c:when>
                        <c:otherwise>
                            <option value="xml">Export to XML file</option>
                        </c:otherwise>
                    </c:choose>
                </select>
                <p class="spacer">&nbsp;</p>

                <label>Choose date interval:</label><br />
                <label for="timeFrom">From:</label>
                <select name="timeFrom" id="timeFrom">
                    <c:forEach var="dateFrom" items="${mdate}" >
                        <c:choose>
                            <c:when test="${dateFrom.equals(param.timeFrom)}" >
                                <c:set var="sel" value="selected=\"selected\"" />
                            </c:when>
                            <c:otherwise>
                                <c:set var="sel" value="" />
                            </c:otherwise>
                        </c:choose>
                        <option value="${dateFrom}" ${sel}>${dateFrom}</option>
                    </c:forEach>
                </select>
                <label for="timeTo">To:</label>
                <select name="timeTo" id="timeTo">
                    <c:forEach var="dateTo" items="${mdate}" >
                        <c:choose>
                            <c:when test="${dateTo.equals(param.timeTo)}" >
                                <c:set var="sel" value="selected=\"selected\"" />
                            </c:when>
                            <c:otherwise>
                                <c:set var="sel" value="" />
                            </c:otherwise>
                        </c:choose>
                        <option value="${dateTo}" ${sel}>${dateTo}</option>                           
                    </c:forEach>
                </select>
                <p class="spacer">&nbsp;</p>

                <input type="submit" name="visualize" value="Visualize" />
            </div>
        </form>
    </div>
</c:if>
<c:if test="${not empty toVisualize}">
    <div id="visualizer">
        <c:choose>
            <c:when test="${param.sensorAction == 'plot_single'}">
                <c:forEach var="sensor" items="${toVisualize}" >
                    <img alt="Plot visualization of measured values" src="${pageContext.request.contextPath}/drawPlot?sensorID=${sensor}&amp;from=${param.timeFrom}&amp;to=${param.timeTo}"/>
                    <p class="spacer"></p>
                </c:forEach>
            </c:when>
            <c:when test="${param.sensorAction == 'plot_all'}">
                <img alt="Plot visualization of measured values" src="${pageContext.request.contextPath}/drawMultiPlot?sensorID=${sensorListIDObj}&amp;from=${param.timeFrom}&amp;to=${param.timeTo}" />
                <p class="spacer"></p>
            </c:when>
            <c:when test="${param.sensorAction == 'map'}">
                <c:forEach var="sensor" items="${toVisualize}" >
                    <img alt="Image map visualization of measured values" src="${pageContext.request.contextPath}/drawMap?sensorID=${sensor}&amp;from=${param.timeFrom}&amp;to=${param.timeTo}"/>
                    <p class="spacer"></p>
                </c:forEach>
            </c:when>
            <c:when test="${param.sensorAction == 'xml'}">
                <a target="_blank" href="${pageContext.request.contextPath}/exportXML?sensorID=${sensorListIDObj}&amp;from=${param.timeFrom}&amp;to=${param.timeTo}">Download XML File</a>
            </c:when>
        </c:choose>
    </div>
</c:if>